package com.wzq.solution;

class Solution1001 {
    public int[] gridIllumination(int N, int[][] lamps, int[][] queries) {
        int len = queries.length;
        int[] rst = new int[len];
        for(int i=0;i<len;i++){
            rst[i] = isLight(lamps,queries[i]);
            closeLamp(lamps,queries[i]);
        }
            
        return rst;
    }
    
    private void closeLamp(int[][] lamps,int[] query){
        int x1 = query[0];
        int y1 = query[1];
        for(int i=0;i<lamps.length;i++){
            
            int x = lamps[i][0];
            int y = lamps[i][1];
            
            if((x-x1)>=-1 && (x-x1)<=1 && (y-y1)>=-1 && (y-y1)<=1 ){
                lamps[i][0]=-1;
                lamps[i][1]=-1;
            }
            
        }
        
    }
    
    private int isLight(int[][] lamps,int[] query){
        
        int x1 = query[0];
        int y1 = query[1];
        for(int i=0;i<lamps.length;i++){
            
            int x = lamps[i][0];
            int y = lamps[i][1];
            
            if(x!=-1 && (x==x1 || y==y1 || x-y==x1-y1 || x+y==x1+y1)){
                return 1;
            }
            
        }
        return 0;
    }
    
}